<?php

namespace common\modules\wechat\controllers\frontend;

use common\modules\wechat\components\BaseController;
use common\modules\wechat\models\Account;
use yii\web\NotFoundHttpException;

/**
 * JS SDK接口
 *
 * @package common\modules\wechat\controllers\frontend
 */
class JsController extends BaseController
{

    /**
     * @param int $id 首页
     */
    public function actionIndex($id)
    {
    }

    /**
     * @var Account
     */
    private $_wechat;

    /**
     * 设置当前公众号
     *
     * @param Account $wechat
     * @return mixed|void
     */
    public function setWechat(Account $wechat)
    {
        $this->_wechat = $wechat;
    }

    /**
     * @return Account
     * @throws NotFoundHttpException
     */
    public function getWechat()
    {
        if ($this->_wechat === null)
        {
            throw new NotFoundHttpException('The "wechat" property must be set.');
        }
        return $this->_wechat;
    }

    /**
     * 根据ID查找公众号
     *
     * @param $id
     * @return Account
     * @throws NotFoundHttpException
     */
    protected function findWechat($id)
    {
        if (($model = Account::findOne($id)) !== null)
        {
            return $model;
        }
        else
        {
            throw new NotFoundHttpException('The requested page does not exist.');
        }
    }
}
